package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JdbcDemo5 {
    public static void main(String[] args) {
        /*
        查询所有用户名，密码，年龄
         */
        try( Connection connection = DBUtil.getConnection()) {
           Statement statement = connection.createStatement();
           String sql = "SELECT username,password,age FROM userinfo";
           ResultSet r = statement.executeQuery(sql);
           while(r.last()) {
               String username = r.getString("username");
               String password = r.getString("password");
               int age = r.getInt("age");
               System.out.println(username + " -" + password + "- " + age);
           }

        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
